package group2assignone.view.administrator;

import group2assignone.func.UCCtoALAdapter;
import group2assignone.model.Manager;
import group2assignone.ucm.administrator.UCCancelAddManager;
import group2assignone.ucm.administrator.UCSaveNewManager;
import group2assignone.view.OurView;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;

/**
 *This class
 * public class AddNewManagerView extends OurView
 * extends ourview. it is the  view which is created to enable adding a new manager
 * it has text fields for all manager details.
 *
 * @author group2
 */
public class AddNewManagerView extends OurView {

    private JTextField firstName = new JTextField();
    private JTextField lastName = new JTextField();
    private JTextField birthDate = new JTextField();
    private JTextField userName = new JTextField();
    private JTextField pWord = new JTextField();
    private JLabel titleLabel = new JLabel("~~~~~~~~~| Please Enter New Manager Details |~~~~~~~~~");
    private JLabel firstNameLabel = new JLabel("First Name");
    private JLabel lastNameLabel = new JLabel("Last Name");
    private JLabel dOBLabel = new JLabel("Date of Birth");
    private JLabel pWordLabel = new JLabel("Password");
    private JLabel uNameLabel = new JLabel("User Name");
    private JButton saveButton = new JButton("Save");
    private JButton cancelButton = new JButton("Cancel");

    @Override
    public void addComponents() {

        setTitle("Add New Manager Interface");
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // dont end program. just go back to last page

        centerPanel.setLayout(new GridLayout(6, 2, 5, 0));

        centerPanel.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));
        centerPanel.add(firstNameLabel);
        centerPanel.add(firstName);
        centerPanel.add(lastNameLabel);
        centerPanel.add(lastName);
        centerPanel.add(dOBLabel);
        centerPanel.add(birthDate);
        centerPanel.add(uNameLabel);
        centerPanel.add(userName);
        centerPanel.add(pWordLabel);
        centerPanel.add(pWord);
        northPanel.add(titleLabel);
        southPanel.add(cancelButton);
        southPanel.add(saveButton);

        pack();

        saveButton.addActionListener(new UCCtoALAdapter(new UCSaveNewManager(this)));
        cancelButton.addActionListener(new UCCtoALAdapter(new UCCancelAddManager(this)));

        centerPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        northPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        southPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
    }

    /**
     * loads the text fields into the corresponding
     * customer fields for the 'new manager'
     * @param newMan
     */
    public void upLoad(Manager newMan) {
        newMan.setUsername(userName.getText());
        newMan.setPassword(pWord.getText());
        newMan.setDob(birthDate.getText());
        newMan.setFName(firstName.getText());
        newMan.setLName(lastName.getText());
    }
}
